import unittest
from ddt import ddt, data
from openpyxl import load_workbook

from openpyxl import *


# class excel():
#     def __init__(self, file):
#         self.file = file
#         self.wb = load_workbook(self.file)
#         sheets = self.wb.get_sheet_names()
#         self.sheet = sheets[0]
#         self.ws = self.wb[self.sheet]
#
#     # 获取表格的总行数和总列数
#     def getRowsClosNum(self):
#         rows = self.ws.max_row
#         columns = self.ws.max_column
#         return rows, columns
#
#     # 获取某个单元格的值
#     def getCellValue(self, row, column):
#         cellvalue = self.ws.cell(row=row, column=column).value
#         return cellvalue
#
#     # 获取某列的所有值
#     def getColValues(self, column):
#         rows = self.ws.max_row
#         columndata = []
#         for i in range(1, rows + 1):
#             cellvalue = self.ws.cell(row=i, column=column).value
#             columndata.append(cellvalue)
#         return columndata
#
#     # 获取某行所有值
#     def getRowValues(self, row):
#         columns = self.ws.max_column
#         rowdata = []
#         for i in range(1, columns + 1):
#             cellvalue = self.ws.cell(row=row, column=i).value
#             rowdata.append(cellvalue)
#         return rowdata
#
#     # 设置某个单元格的值
#     def setCellValue(self, row, colunm, cellvalue):
#         try:
#             self.ws.cell(row=row, column=colunm).value = cellvalue
#             self.wb.save(self.file)
#         except:
#             self.ws.cell(row=row, column=colunm).value = "writefail"
#             self.wb.save(self.file)
#


class Do_Excel:
    def __init__(self, filename, sheet_name):
        self.filename = filename
        self.fn = load_workbook(self.filename)  # 打开文件
        self.sheet_name = sheet_name
        self.sheet = self.fn[self.sheet_name]

    # 写入文件
    def write_excel(self, h, l, val):
        self.sheet.cell(h, l).value = val  # 执行结果
        self.fn.save(filename=self.filename)
        self.fn.close()

    # 获取表格的总行数
    def getMaxNumH(self):
        rows = self.sheet.max_row
        return rows

    # 获取表格的总列数
    def getMaxNumL(self):
        columns = self.sheet.max_column
        return columns


if __name__ == '__main__':
    # 写入
    excel = Do_Excel("../report/report.xlsx", 'Sheet1')
    # excel.write_excel(l=1, h=2, val="11")
    # excel.write_excel(l=2, h=2, val="02")
    # excel.write_excel(l=3, h=2, val="03")
    # excel.write_excel(l=4, h=2, val="04")
    # excel.write_excel(l=5, h=2, val="05")
    print(excel.getMaxNumL())
    print(excel.getMaxNumH()+1)
